package com.huonan.utils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Description TODO
 * @Author huonan
 * @Date 2021/9/9 下午3:35
 * @Version V1.0
 **/
public class MD5Util {

    public static String encryption(String strStr) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update((strStr).getBytes(StandardCharsets.UTF_8));
        } catch (NoSuchAlgorithmException error) {
            error.printStackTrace();
        }
        assert md5 != null;
        byte[] b = md5.digest();
        int i;
        StringBuilder buf = new StringBuilder("");

        for (byte value : b) {
            i = value;
            if (i < 0) {
                i += 256;
            }
            if (i < 16) {
                buf.append("0");
            }
            buf.append(Integer.toHexString(i));
        }
        return buf.toString();
    }
}
